package com.cjm.algorithm.queue;

import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class EvalRPN150 {
    private static final List<String> abc = Arrays.asList("+", "-", "*", "/");
    public int evalRPN(String[] tokens) {
        Stack<Integer> x = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String token = tokens[i];
            if (!abc.contains(token)) {
                x.push(Integer.valueOf(token));
                continue;
            }
            Integer second = x.pop();
            Integer first = x.pop();
            if ("+".equals(token)) {
                x.push(first + second);
            } else if ("-".equals(token)) {
                x.push(first - second);
            } else if ("*".equals(token)) {
                x.push(first * second);
            } else if ("/".equals(token)) {
                x.push(first / second);
            }
        }
        return x.pop();
    }

    public static void main(String[] args) {
        EvalRPN150 x = new EvalRPN150();
        int i = x.evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"});
        System.err.println(i);
    }
}
